﻿using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Xml.Serialization;

namespace System
{
  [DebuggerStepThrough]
  public static class SerializationExtensions
  {

    public static T Deserialize<T>(this string xml) where T : new()
    {
      XmlSerializer xml_s = new XmlSerializer(typeof(T));
      StringReader sr = new StringReader(xml);
      try
      {
        return (T)xml_s.Deserialize(sr);
      }
      catch (Exception ex)
      {
        ex.Log();
        return new T();
      }
    }
    public static string Serialize<T>(this T obj)
    {
      XmlSerializer xml_s = new XmlSerializer(typeof(T));
      StringWriter sw = new StringWriter();
      xml_s.Serialize(sw, obj);
      return sw.ToString();
    }

  }
}